<script setup lang="ts">
import { onLaunch } from '@dcloudio/uni-app'
import { useAppStore } from './stores/app'
import { useUserStore } from './stores/user'
import wechatOa, { UrlScene } from './utils/wechat'
const appStore = useAppStore()
const { getUser } = useUserStore()

onLaunch(async (options) => {
    await appStore.getConfig()
    // #ifdef H5
    const { status, page_status, page_url } = appStore.getH5Config
    if (status == 0) {
        if (page_status == 1) return (location.href = page_url)
        uni.reLaunch({ url: '/pages/empty/empty' })
    }
    if (options?.query.code && options?.query.scene == UrlScene.LOGIN) {
        uni.reLaunch({ url: '/pages/login/login?code=' + options?.query.code })
    } else if (options?.query.code && options?.query.scene == UrlScene.BIND_WX) {
        uni.reLaunch({ url: '/pages/user_set/user_set?code=' + options?.query.code })
    }
    // #endif

    // #ifdef MP-WEIXIN
    //ios音频静音模式播放
    uni.setInnerAudioOption({
        obeyMuteSwitch: false
    })
    //热更新
    const updateManager = uni.getUpdateManager()
    updateManager.onCheckForUpdate(function (res) {
        // 请求完新版本信息的回调
        console.log(res.hasUpdate)
    })
    updateManager.onUpdateReady(function () {
        uni.showModal({
            title: '更新提示',
            content: '新版本已经准备好，是否重启应用？',
            success(res) {
                if (res.confirm) {
                    // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                    updateManager.applyUpdate()
                }
            }
        })
    })
    updateManager.onUpdateFailed(function () {
        // 新版本下载失败
    })

    // #endif

    await getUser()
})
</script>
<style lang="scss">
//
</style>
